package com.cms.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.cms.entity.base.BaseWechatMenu;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Entity - 微信菜单
 * 
 * 
 * 
 */
@SuppressWarnings("serial")
@EqualsAndHashCode(callSuper = false)
@TableName("cms_wechat_menu")
public class WechatMenu extends BaseWechatMenu {
	
	/**
	 * 下级微信菜单
	 */
	@TableField(exist=false)
	@JSONField(serialize=false)  
	private List<WechatMenu> subMenus;
	
	
	/**
	 * 获取下级微信菜单
	 * 
	 * @return 下级微信菜单
	 */
	public List<WechatMenu> getSubMenus() {
		if(subMenus == null){
			List<Map<String,Object>> maps = SqlRunner.db().selectList("select * from cms_wechat_menu where parentId={0} order by sort asc",getId());
			subMenus = maps.stream().map(i-> JSON.parseObject(JSON.toJSONString(i), WechatMenu.class)).collect(Collectors.toList());
		}
		return subMenus;
	}
	

}
